<template>
  <div class="ele-body">
    <a-card :bordered="false" title="修改货品">
      <div>
        <div class="fs-16 fw-bolder margin-bottom-15">采购信息</div>
        <table cellpadding="0" cellspacing="0" class="recepit_table2">
          <tbody>
            <tr>
              <td class="tit">收货方式</td>
              <td>{{ goods_info.purchase_receive_type_name || '' }}</td>
              <td class="tit">货品类别</td>
              <td>{{ goods_info.goods_category_type_name || '' }}</td>
              <td class="tit">入库位置</td>
              <td>{{ goods_info.warehouse_code_name || '' }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="fs-16 fw-bolder margin-y-15">货品信息</div>
      <a-form
        :label-col="{ md: { span: 12 }, sm: { span: 12 }, xs: { span: 24 } }"
        :wrapper-col="{ md: { span: 12 }, sm: { span: 12 }, xs: { span: 24 } }"
      >
        <a-row :gutter="24">
          <a-col
            :md="6"
            :sm="12"
            :xs="12"
            v-for="(item, index) in firstArr"
            :key="index"
          >
            <selectinp
              ref="selectinpRef"
              v-model:value="form[item.value]"
              :dataValue="form[item.value]"
              :itemData="item"
              :thumb_url="thumb_url"
              :validateInfos="validateInfos"
              @getImg="getImg"
              @getImgUrl="getImgUrl"
              @getSeriesStyle="getSeriesStyle"
              @get_subclass="getSubClass"
            />
          </a-col>
          <a-col
            v-show="searchExpand"
            :md="6"
            :sm="12"
            :xs="12"
            v-for="(item, index) in lastArr"
            :key="index"
          >
            <selectinp
              ref="selectinpRef"
              v-model:value="form[item.value]"
              :dataValue="form[item.value]"
              :itemData="item"
              :thumb_url="thumb_url"
              :validateInfos="validateInfos"
              @getImg="getImg"
              @getImgUrl="getImgUrl"
              @getSeriesStyle="getSeriesStyle"
              @get_subclass="getSubClass"
            />
          </a-col>
          <a-col :md="6" :sm="12" :xs="12" :offset="18">
            <a-form-item label="" class="text-right">
              <a @click="toggleExpand">
                <span v-if="searchExpand">
                  收起
                  <up-outlined class="ele-text-small" />
                </span>
                <span v-else>
                  更多信息
                  <down-outlined class="ele-text-small" />
                </span>
              </a>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div>
        <div class="fs-16 fw-bolder margin-bottom-15">主石信息</div>
        <div>
          <vxe-table
            border
            ref="xTable1"
            :edit-config="{ trigger: 'click', mode: 'cell', showIcon: false }"
            :data="mainStone.tableData"
          >
            <vxe-column type="seq" title="NO" width="60" fixed="left" />
            <vxe-column
              ref="table1111"
              v-for="config in mainStone.tableColumn"
              :key="config.key"
              :field="config.field"
              :title="config.title"
              :fixed="config.fixed"
              :width="config.width"
              :params="{ type: config.inputType, options: config.options }"
              :edit-render="{}"
            >
              <template #default="{ column, row }">
                <span
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  >{{
                    productSpec(column.params.options, row[config.field])
                  }}</span
                >
                <span v-else>{{ row[config.field] }}</span>
              </template>
              <template #edit="{ column, row }">
                <vxe-select
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  v-model="row[config.field]"
                  placeholder="请选择"
                  transfer
                  clearable
                >
                  <vxe-option
                    v-for="item in column.params.options"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </vxe-select>
                <vxe-input
                  v-else
                  v-model="row[config.field]"
                  type="text"
                  placeholder="请输入"
                />
              </template>
            </vxe-column>
          </vxe-table>
          <vxe-toolbar>
            <template #buttons>
              <vxe-button @click="insertEvent1(-1)" v-show="length1 < 2"
                >新增</vxe-button
              >
            </template>
          </vxe-toolbar>
        </div>
      </div>
      <div>
        <div class="fs-16 fw-bolder margin-bottom-15">副石信息</div>
        <div>
          <vxe-table
            border
            ref="xTable2"
            :edit-config="{ trigger: 'click', mode: 'cell', showIcon: false }"
            :data="viceStone.tableData"
          >
            <vxe-column type="seq" title="NO" width="60" fixed="left" />
            <vxe-column
              ref="table2222"
              v-for="config in viceStone.tableColumn"
              :key="config.key"
              :field="config.field"
              :title="config.title"
              :fixed="config.fixed"
              :width="config.width"
              :params="{ type: config.inputType, options: config.options }"
              :edit-render="{}"
            >
              <template #default="{ column, row }">
                <span
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  >{{
                    productSpec(column.params.options, row[config.field])
                  }}</span
                >
                <span v-else>{{ row[config.field] }}</span>
              </template>
              <template #edit="{ column, row }">
                <vxe-select
                  v-if="
                    column.params.type == 'select' ||
                    column.params.type == 'selectajax'
                  "
                  v-model="row[config.field]"
                  placeholder="请选择"
                  transfer
                  clearable
                >
                  <vxe-option
                    v-for="item in column.params.options"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  />
                </vxe-select>
                <vxe-input
                  v-else
                  v-model="row[config.field]"
                  type="text"
                  placeholder="请输入"
                />
              </template>
            </vxe-column>
          </vxe-table>
          <vxe-toolbar>
            <template #buttons>
              <vxe-button @click="insertEvent2(-1)" v-show="length2 < 3"
                >新增</vxe-button
              >
            </template>
          </vxe-toolbar>
        </div>
      </div>
    </a-card>
    <div style="width: 100%; height: 100px"></div>
    <!-- 底部工具栏 -->
    <div class="ele-bottom-tool">
      <div class="ele-bottom-tool-actions">
        <a-space size="large">
          <a-button type="primary" :loading="loading" @click="save()"
            >保存</a-button
          >
          <a-button
            type="default"
            class="btn"
            :loading="loading"
            @click="goBack()"
            >取消</a-button
          >
        </a-space>
      </div>
    </div>
  </div>
</template>

<script setup>
  import {
    ref,
    reactive,
    unref,
    onMounted,
    defineComponent,
    computed
  } from 'vue';
  import {
    DownOutlined,
    UpOutlined,
    PlusOutlined,
    LoadingOutlined
  } from '@ant-design/icons-vue';
  import { useRouter } from 'vue-router';
  import { message, Modal, Form } from 'ant-design-vue';
  import { finishPageTab } from '@/utils/page-tab-util';
  import { uploadUrl } from '@/config/setting';
  import { isEmptyFn } from '@/utils/objIsEmpty.js';
  import selectinp from '@/components/zbInput/huopinSelectInput.vue';
  import {
    get_broad_class_list,
    get_subclass_list,
    get_quality_list,
    get_style_list,
    get_supplier_list,
    get_supplier_style_list,
    get_series_list,
    get_series_style_list,
    get_gift_list,
    get_technology_list,
    get_price_category_list,
    get_gem_category_list,
    get_finance_list,
    get_gem_attribute_list,
    add_goods,
    goods_detail,
    get_column_templete_list,
    get_store_brand_list,
    get_brand_list,
    get_classes_list,
    get_metal_color_list,
    get_labor_category_list,
    get_stone_weight_list
  } from '@/api/jewelry/receipts_purchase';
  import { alter, get_goods_detail } from '@/api/jewelry/receipts_alter_goods';
  import {
    get_broad_class_select,
    get_subclass_select,
    get_quality_select,
    get_brand_select,
    get_series_select,
    get_store_brand_select,
    get_gift_select,
    get_technology_select,
    get_price_category_select,
    get_gem_category_select,
    get_classes_select,
    get_metal_color_select,
    get_labor_category_select,
    get_finance_select,
    get_stone_weight_select,
    get_supplier_select,
    get_series_style_select,
    get_gem_attribute_select
  } from '@/api/material/select';
  import { forIn } from 'lodash-es';

  const useForm = Form.useForm;
  const loading = ref(false);
  const { currentRoute, push } = useRouter();
  const { query } = unref(currentRoute);

  // 是否展开
  const searchExpand = ref(false);
  const goods_info = ref({});
  const arrParmas = ref([]);
  const form = reactive({});
  const rules = reactive({});
  const thumb_url = ref(null);
  // 默认显示的
  const firstArr = ref(null);
  // 默认隐藏的
  const lastArr = ref(null);
  //主石
  const mainStone = reactive({
    tableColumn: [],
    tableData: []
  });
  //副石
  const viceStone = reactive({
    tableColumn: [],
    tableData: []
  });
  onMounted(async () => {
    //货品信息
    await get_column_templete_list({
      filters: {
        receipts_type: 1,
        goods_category_code: query.goods_category_code,
        type: 'sku_info'
      }
    }).then(async (res) => {
      arrParmas.value = [];
      let list = [];
      await res.row_list.forEach((item, index) => {
        if (item.column_type != 'count') {
          list.push(item);
        }
      });

      await list.forEach(async (item, index) => {
        if (item.status == 1) {
          /* if (item.column_type != 'count') {
					list.push(item);
				} */
          await arrParmas.value.push({
            type: item.column_type,
            label: item.name,
            value: item.column,
            params: item.params ? item.params : '',
            options:
              item.column == 'retail_type' || item.column == 'labor_type'
                ? item.params
                : [],
            require: item.require,
            disabled:
              item.column == 'bar_code' || item.column == 'num' ? true : false
          });
          if (item.column == 'retail_type' || item.column == 'labor_type') {
            arrParmas.value[index].options = item.params;
          }
          if (item.column == 'num') {
            form[item.column] = 1;
          } else {
            form[item.column] = null;
          }
          rules[item.column] = [
            {
              required: item.require == 1 ? true : false,
              message:
                item.column_type == 'select' ||
                item.column_type == 'selectajax' ||
                item.column_type == 'selectajaxlike' ||
                item.column_type == 'image'
                  ? `请选择${item.name}`
                  : `请输入${item.name}`,
              trigger: 'blur'
            }
          ];
        }
      });

      firstArr.value = arrParmas.value.slice(0, 20);
      lastArr.value = arrParmas.value.slice(20, arrParmas.value.length);
    });
    //主石信息
    mainStone.tableColumn = [];
    await get_column_templete_list({
      filters: {
        receipts_type: 1,
        goods_category_code: query.goods_category_code,
        type: 'main_stone'
      }
    }).then(async (res) => {
      let obj = {};
      await res.row_list.forEach((item, index) => {
        if (item.status == 1) {
          mainStone.tableColumn.push({
            key: index,
            type: item.column_type,
            inputType: item.column_type,
            title: item.name,
            field: item.column,
            require: item.require,
            width: 150
          });
          obj[item.column] = '';
          //obj.type = 1;
        }
      });
      mainStone.tableData.push(obj);

      console.log('mainStone.tableData', mainStone.tableData);
    });
    await getDetail();
    //副石信息
    viceStone.tableColumn = [];
    await get_column_templete_list({
      filters: {
        receipts_type: 1,
        goods_category_code: query.goods_category_code,
        type: 'vice_stone'
      }
    }).then(async (res) => {
      let obj = {};
      await res.row_list.forEach((item, index) => {
        if (item.status == 1) {
          viceStone.tableColumn.push({
            key: index,
            type: item.column_type,
            inputType: item.column_type,
            title: item.name,
            field: item.column,
            require: item.require,
            width: 150
          });
          obj[item.column] = '';
          //obj.type = 2;
        }
      });
      viceStone.tableData.push(obj);
    });
    //货品大类
    await get_broad_class_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'class_code') {
          item.options = res;
        }
      });
    });
    //货品小类
    await get_subclass_select({
      page: 1,
      page_size: 9999,
      filters: { class_code: form.class_code }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'subclass_code') {
          item.options = res;
        }
      });
    });
    //成色
    await get_quality_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'quality_code') {
          item.options = res;
        }
      });
    });
    //门店品牌
    await get_store_brand_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'store_brand_code') {
          item.options = res;
        }
      });
    });
    //经营品牌
    await get_store_brand_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'brand_code') {
          item.options = res;
        }
      });
    });
    //系列名称
    await get_series_select({ page: 1, page_size: 9999 }).then(async (res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'series_code') {
          item.options = res;
        }
      });
      //await getSeriesStyle(form.series_code);
    });
    //系列款式
    await get_series_style_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'series_style_code') {
          item.options = res;
        }
      });
    });
    //赠品类型
    await get_gift_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'gift_code') {
          item.options = res;
        }
      });
    });
    //工艺类型
    await get_technology_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'technology_code') {
          item.options = res;
        }
      });
    });
    //价格类型
    await get_price_category_select({ page: 1, page_size: 9999 }).then(
      (res) => {
        arrParmas.value.forEach((item) => {
          if (item.value == 'price_category_code') {
            item.options = res;
          }
        });
      }
    );
    //宝石类别
    await get_gem_category_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'gem_category_code') {
          item.options = res;
        }
      });
    });
    //货品品类
    await get_classes_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'classes_code') {
          item.options = res;
        }
      });
    });
    //贵金属颜色
    await get_metal_color_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'metal_color_code') {
          item.options = res;
        }
      });
    });
    //工费类型
    await get_labor_category_select({ page: 1, page_size: 9999 }).then(
      (res) => {
        arrParmas.value.forEach((item) => {
          if (item.value == 'labor_category_code') {
            item.options = res;
          }
        });
      }
    );
    //财务类型
    await get_finance_select({ page: 1, page_size: 9999 }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'finance_code') {
          item.options = res;
        }
      });
    });
    //宝石属性  颜色
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'color'
      }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (
          item.value == 'cert_first_color' ||
          item.value == 'cert_second_color'
        ) {
          item.options = res;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'color') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'color') {
          item.options = res;
        }
      });
    });
    //宝石属性  切工
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'cut'
      }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'cert_first_cut' || item.value == 'cert_second_cut') {
          item.options = res;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'cut') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'cut') {
          item.options = res;
        }
      });
    });
    //宝石属性  形状
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'form'
      }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (
          item.value == 'cert_first_form' ||
          item.value == 'cert_second_form'
        ) {
          item.options = res;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'form') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'form') {
          item.options = res;
        }
      });
    });
    //宝石属性  净度
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'neatness'
      }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (
          item.value == 'cert_first_neatness' ||
          item.value == 'cert_second_neatness'
        ) {
          item.options = res;
        }
      });
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'neatness') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'neatness') {
          item.options = res;
        }
      });
    });
    //宝石属性  抛光
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'buffing'
      }
    }).then((res) => {
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'buffing') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'buffing') {
          item.options = res;
        }
      });
    });
    //宝石属性  对称
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'symmetric'
      }
    }).then((res) => {
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'symmetric') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'symmetric') {
          item.options = res;
        }
      });
    });
    //宝石属性  荧光
    await get_gem_attribute_select({
      page: 1,
      page_size: 9999,
      filters: {
        type: 'fluorescence'
      }
    }).then((res) => {
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'fluorescence') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'fluorescence') {
          item.options = res;
        }
      });
    });
    //宝石属性  石重范围
    await get_stone_weight_select({ page: 1, page_size: 9999 }).then((res) => {
      mainStone.tableColumn.forEach((item) => {
        if (item.field == 'stone_weight_code') {
          item.options = res;
        }
      });
      viceStone.tableColumn.forEach((item) => {
        if (item.field == 'stone_weight_code') {
          item.options = res;
        }
      });
    });
    //供应商
    await get_supplier_select({
      page: 1,
      page_size: 99999
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'supplier_code') {
          item.options = res;
        }
      });
    });
  });

  const getDetail = (page) => {
    /* goods_detail({ goods_code: query.goods_code }).then(async (res) => {
      let obj = {};
      await res.goods_info.sku_info.forEach((item, index) => {
        if (item.column == 'labor_type') {
          item.value = item.value.toString();
        }
        obj[item.column] = item.value;
      });
      await Object.keys(form).forEach((key) => {
        form[key] = obj[key] ? obj[key] : null;
      });
      form.thumb = form.thumb == 0 ? '' : form.thumb;
      thumb_url.value =
        res.goods_info.thumb_url == 0 ? '' : res.goods_info.thumb_url;
      mainStone.tableData = res.goods_info.master_gem.row_list;
      res.goods_info.master_gem.row_list.forEach((item, index) => {
        Object.keys(mainStone.tableData).forEach((key) => {});
      });
      length1.value = mainStone.tableData.length;
      viceStone.tableData = res.goods_info.vice_gem.row_list;
      length2.value = viceStone.tableData.length;
      goods_info.value = res.goods_info;
    }); */
    get_goods_detail({
      code: query.code,
      goods_code: query.goods_code,
      page: page
    }).then(async (res) => {
      let obj = {};
      await res.goods.sku_info.forEach((item, index) => {
        if (item.column == 'labor_type') {
          item.value = item.value.toString();
        }
        obj[item.column] = item.value;
      });
      await Object.keys(form).forEach((key) => {
        form[key] = obj[key] ? obj[key] : null;
      });
      form.thumb = form.thumb == 0 ? '' : form.thumb;
      thumb_url.value = res.goods.thumb_url == 0 ? '' : res.goods.thumb_url;
      mainStone.tableData = res.goods.master_gem.row_list;
      res.goods.master_gem.row_list.forEach((item, index) => {
        Object.keys(mainStone.tableData).forEach((key) => {});
      });
      length1.value = mainStone.tableData.length;
      viceStone.tableData = res.goods.vice_gem.row_list;
      length2.value = viceStone.tableData.length;
      goods_info.value = res.receipts_detail;
      console.log('res===', goods_info.value);
    });
  };

  //系列款式
  const getSeriesStyle = (val) => {
    //每次系列名称修改， 系列款式联动
    form.series_style_code = null;
    get_series_style_select({
      page: 1,
      page_size: 9999,
      filters: { series_code: val }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'series_style_code') {
          item.options = res;
        }
      });
    });
  };
  //货品小类
  const getSubClass = (val) => {
    //每次货品大类修改， 货品小类联动
    console.log('货品大类改变', val);
    form.subclass_code = '';
    get_subclass_select({
      page: 1,
      page_size: 9999,
      filters: { class_code: val }
    }).then((res) => {
      arrParmas.value.forEach((item) => {
        if (item.value == 'subclass_code') {
          item.options = res;
        }
      });
    });
  };

  //主石
  const xTable1 = ref(null);
  const length1 = ref(1);
  const insertEvent1 = async (row) => {
    length1.value++;
    const $table = xTable1.value;
    const record = {
      type: 1
    };
    const { row: newRow } = await $table.insertAt(record, row);
    await $table.setEditCell(newRow, 'name');
  };
  const getInsertEvent1 = () => {
    const $table = xTable1.value;
    const insertRecords = $table.getInsertRecords();
    mainStone.tableData = mainStone.tableData.concat(
      JSON.parse(JSON.stringify(insertRecords))
    );
  };
  //副石
  const xTable2 = ref(null);
  const length2 = ref(1);
  const insertEvent2 = async (row) => {
    length2.value++;
    const $table = xTable2.value;
    const record = {
      type: 2
    };
    const { row: newRow } = await $table.insertAt(record, row);
    await $table.setEditCell(newRow, 'name');
  };
  const getInsertEvent2 = () => {
    const $table = xTable2.value;
    const insertRecords = $table.getInsertRecords();
    viceStone.tableData = viceStone.tableData.concat(
      JSON.parse(JSON.stringify(insertRecords))
    );
  };

  const toggleExpand = () => {
    searchExpand.value = !searchExpand.value;
  };

  //根据value寻找label， 用于回显
  const productSpec = (list, code) => {
    //console.log('）））', list, code);
    if (list && list.length > 0) {
      const item = list.find((item) => item.value === code);
      return item ? item.label : code;
    }
  };

  const getImg = (data) => {
    console.log('===', data);
    Object.assign(form, data);
  };
  const getImgUrl = (data) => {
    console.log('&&&', data);
    thumb_url.value = data.url;
  };

  const { validate, validateInfos } = useForm(form, rules);

  const save = async () => {
    validate()
      .then(async () => {
        /* if (mainStone.tableData.length > 0) {
          console.log('主石');
        } */
        await getInsertEvent1();
        /* if (viceStone.tableData.length > 0) {
          console.log('副石');
        } */
        await getInsertEvent2();
        let mainTableData = [];
        let viceTableData = [];
        //主石去空
        mainStone.tableData.forEach((item, index) => {
          if (!isEmptyFn(item)) {
            item.type = 1;
            mainTableData.push(item);
          }
        });
        //副石去空
        viceStone.tableData.forEach((item, index) => {
          if (!isEmptyFn(item)) {
            item.type = 2;
            viceTableData.push(item);
          }
        });
        /* form.gem_item = [];
        form.gem_item = form.gem_item
          .concat(mainTableData)
          .concat(viceTableData); */
        form.code = query.code;
        form.goods_code = query.goods_code;
        if (mainTableData.length == 1) {
          form.main_stone_first = mainTableData[0];
        } else if (mainTableData.length == 2) {
          form.main_stone_first = mainTableData[0];
          form.main_stone_second = mainTableData[1];
        }
        if (viceTableData.length == 1) {
          form.vice_stone_first = viceTableData[0];
        } else if (viceTableData.length == 2) {
          form.vice_stone_first = viceTableData[0];
          form.vice_stone_second = viceTableData[1];
        } else if (viceTableData.length == 3) {
          form.vice_stone_first = viceTableData[0];
          form.vice_stone_second = viceTableData[1];
          form.vice_stone_third = viceTableData[2];
        }
        console.log('form', form);
        alter(form)
          .then((res) => {
            message.success(res.msg);
            setTimeout(() => {
              goBack();
            }, 300);
          })
          .catch((e) => {
            message.error(e);
          });
      })
  };
  const goBack = () => {
    push({
      path: '/purchase/receipts_alter_goods/detail',
      query: { code: query.code }
    });
  };
</script>
